import request from '@/utils/request';

// 查询商品列表
export function listItem(query: Record<string, any>) {
  return request({
    url: '/wms/item/list',
    method: 'get',
    params: query
  })
}

// 查询商品详细
export function getItem(itemId: string | number) {
  return request({
    url: '/wms/item/' + itemId,
    method: 'get'
  })
}

// 新增商品
export function addItem(data: Record<string, any>) {
  return request({
    url: '/wms/item',
    method: 'post',
    data: data
  })
}

// 修改商品
export function updateItem(data: Record<string, any>) {
  return request({
    url: '/wms/item',
    method: 'put',
    data: data
  })
}

// 删除商品
export function delItem(itemId: string | number | string[]) {
  const ids = Array.isArray(itemId) ? itemId.join(',') : itemId;
  return request({
    url: '/wms/item/' + ids,
    method: 'delete'
  })
}

// 导出商品
export function exportItem(query: Record<string, any>) {
  return request({
    url: '/wms/item/export',
    method: 'post',
    data: query
  })
}

// 导入商品
export function importItem(data: FormData) {
  return request({
    url: '/wms/item/import',
    method: 'post',
    data: data
  })
}

// 获取商品分类列表
export function getItemCategories() {
  return request({
    url: '/wms/item/categories',
    method: 'get'
  })
}

// 批量更新商品状态
export function updateItemStatus(ids: number[], status: string) {
  return request({
    url: '/wms/item/status',
    method: 'put',
    data: { ids, status }
  })
}

// ===================== SKU相关API函数 =====================

// 获取商品的SKU列表
export function listSku(itemId: string | number) {
  return request({
    url: `/wms/item/${itemId}/sku/list`,
    method: 'get'
  })
}

// 新增SKU
export function addSku(data: Record<string, any>) {
  return request({
    url: '/wms/sku',
    method: 'post',
    data: data
  })
}

// 修改SKU
export function updateSku(data: Record<string, any>) {
  return request({
    url: '/wms/sku',
    method: 'put',
    data: data
  })
}

// 删除SKU
export function delSku(skuId: string | number) {
  return request({
    url: '/wms/sku/' + skuId,
    method: 'delete'
  })
}




